//
//  SEGOrderPayCell.m
//  ExcellentHome
//
//  Created by Chiang on 2017/12/25.
//  Copyright © 2017年 陈区. All rights reserved.
//

#import "SEGOrderPayCell.h"

@implementation SEGOrderPayCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setUpUI];
    }
    return self;
}

-(void)setUpUI {
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.priceLabel];
    [self.contentView addSubview:self.unitLabel];
    
    [_titleLabel sizeToFit];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(15);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.width.mas_equalTo(150);
    }];
    
    [_priceLabel sizeToFit];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_titleLabel.mas_centerY);
        make.right.equalTo(self.contentView.mas_right).offset(-15);
    }];
    
    [_unitLabel sizeToFit];
    [_unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_titleLabel.mas_centerY);
        make.right.equalTo(_priceLabel.mas_left).offset(-60);
    }];
}

-(void)setIndexPath:(NSIndexPath *)indexPath {
    _indexPath = indexPath;
}

-(void)setDataDic:(NSDictionary *)dataDic {
    if (_indexPath.section == 0) {
        _unitLabel.hidden = YES;
        [_titleLabel extendAttributedString:dataDic[@"serviceName"] lineSpace:LINESPACE_6 font:kFont_16 width:150];
        NSString *price =dataDic[@"price"];
        _priceLabel.text = [NSString stringWithFormat:@"%.2f元",[price floatValue]/100];
    } else {
        _unitLabel.hidden = NO;
        [_titleLabel extendAttributedString:dataDic[@"goodsName"] lineSpace:LINESPACE_6 font:kFont_16 width:150];
        NSString *price =dataDic[@"price"];
        _priceLabel.text = [NSString stringWithFormat:@"%.2f元",[price floatValue]/100];
        _unitLabel.text = [NSString stringWithFormat:@"%@%@",dataDic[@"useCount"],dataDic[@"unit"]];
    }
}

-(UILabel*)titleLabel {
    if (!_titleLabel) {
        _titleLabel=[[UILabel alloc] init];
        _titleLabel.textColor=kColor_1;
        _titleLabel.font=kFont_16;
        _titleLabel.numberOfLines = 0;
        _titleLabel.lineBreakMode = NSLineBreakByCharWrapping;
    }
    return _titleLabel;
}

-(UILabel*)priceLabel {
    if (!_priceLabel) {
        _priceLabel=[[UILabel alloc] init];
        _priceLabel.textColor=kColor_1;
        _priceLabel.font=kFont_16;
    }
    return _priceLabel;
}

-(UILabel*)unitLabel {
    if (!_unitLabel) {
        _unitLabel=[[UILabel alloc] init];
        _unitLabel.textColor=kColor_1;
        _unitLabel.font=kFont_16;
    }
    return _unitLabel;
}
@end
